<?php

namespace frontend\models;

/**
 * @author  shuang
 * @date    2016-10-30 20:48:32
 * @version V1.0
 * @desc    
 */
use common\models\UserOrder;
use yii\behaviors\TimestampBehavior;
use common\components\MTools;
use Yii;

class WB_UserOrder extends UserOrder {
    /*
     * 设置表操作行为动作
     * return array
     */

    public function behaviors() {
        return[
            [
                'class' => TimestampBehavior::className()
            ]
        ];
    }

    /*
     * 插入、更新数据
     * @params $data array
     * @params $id int 主键
     * return boolean 
     */

    public static function createData() {
        $model = new WB_UserOrder();
        try {
            $model->id = MTools::makeProductNumber();
            $model->userid = Yii::$app->user->id;
            $model->username = Yii::$app->user->identity->username;
            $model->amount = Yii::$app->request->post("txtmoney");
            $model->type = Yii::$app->request->post("nametype");
            $model->isupgrade = Yii::$app->request->post("upgrade",0);
            $model->status = 1;
            if ($model->save()) {
                return $model->id;
            } else {
                return false;
            }
        } catch (Exception $e) {
            throw $e;
        }
    }

//交易状态
    public static $order_status = [
        1 => "等待支付",2=>"支付成功"
    ];

}
